import { chatHttp } from '@/utils/request';
import type { IRes } from '@/utils/request';
import type {
	IFriendInfo,
	IFriendGroupListItem,
	IUpdateFriendInfo,
	ICreateFriendGroup,
	IGroupChatItem
} from './type';
import type { IFriendGroupItem, IGroupChatInfo } from '../../c-cpns/CreateGroupChatModal/type';

// 获取好友列表
export const getFriendList = () =>
	chatHttp.get<IRes<IFriendGroupItem[]>>({ url: 'friend/friend_list' });

// 根据 id 获取好友信息
export const getFriendInfoById = (id: number) =>
	chatHttp.get<IRes<IFriendInfo>>({
		url: `friend/friend_id/?id=${id}`
	});

// 获取分组列表
export const getFriendGroup = () =>
	chatHttp.get<IRes<IFriendGroupListItem[]>>({
		url: 'friend/group_list'
	});

// 修改好友信息
export const updateFriendInfo = (data: IUpdateFriendInfo) =>
	chatHttp.post<IRes>({
		url: 'friend/update_friend',
		data
	});

// 新建分组
export const createFriendGroup = (data: ICreateFriendGroup) =>
	chatHttp.post<IRes>({
		url: 'friend/create_group',
		data
	});

// 获取群聊列表
export const getGroupChatList = () =>
	chatHttp.get<IRes<IGroupChatItem[]>>({
		url: 'group/group_list'
	});

// 获取群聊信息
export const getGroupChatInfo = (group_id: number) =>
	chatHttp.get<IRes<IGroupChatInfo>>({
		url: `group/group_info?group_id=${group_id}`
	});
